<template>
  <div class="info-title" :style="[getActStyle.base, {color: titleColor}]" :class="getActCls.base" v-if="isShow">
    <div v-if="getActStyle.left|| getActCls.left" :style="[getActStyle.left, {background: titleColor}]"
         :class="getActCls.left" class="icon">
      <img :src="getIcon"/>
    </div>
    <div class="name" :style="[getActStyle.name, {borderColor: titleColor}]" :class="getActCls.name">
      <RInput v-model="text" hint="自定义标题..."/>
    </div>
    <div v-if="right || getActStyle.right || getActCls.right" :style="getActStyle.right" :class="getActCls.right"></div>
  </div>
  <div class="info-title" :style="[getActStyle.base]" :class="getActCls.base" v-else-if="!isShow && isFixed"></div>
</template>

<script>
import RInput from './RInput'

export default {
  name: 'RTitle',
  data () {
    return {
      text: ''
    }
  },
  props: ['titleColor', 'left', 'name', 'right', 'value', 'isShow', 'isFixed', 'icon'],
  components: {
    RInput
  },
  created () {
    this.text = this.value
  },
  computed: {
    getTitleInfo () {
      return this.$parent.$parent.getCustomizeTitle
    },
    getActStyle () {
      return this.getTitleInfo.style
    },
    getActCls () {
      return this.getTitleInfo.class
    },
    getIcon () {
      return this.left || require(`@/assets/resume/title/${this.icon}.svg`)
    }
  },
  watch: {
    value: function (newVal) {
      this.text = newVal
    },
    text: function (newVal) {
      newVal = newVal || null
      this.$emit('input', newVal)
    }
  }
}
</script>

<style scoped lang="less">
  .info-title {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    font-size: 20px;
    font-weight: bold;
    align-items: center;

    /*未完成*/

    .border {
      content: "";
      width: 40px;
      height: 1px;
      top: 1px;
      background: black;
      display: inline-block;
      position: relative;
    }

    .before-line:before {
      .border();
    }

    .after-line:after {
      .border();
    }

    .underline {
      border-bottom: 1px solid;
    }

    .icon {
      width: 25px;
      height: 25px;
      border-radius: 12.5px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 5px;

      img {
        width: 15px;
        height: 15px;
      }
    }
  }

</style>
